package com.yu.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class ListValueValidator implements ConstraintValidator<ListValue, Integer> {

    private Set<Integer> vals= new HashSet<>();

    // 初始化信息
    @Override
    public void initialize(ListValue constraintAnnotation) {
        int[] value = constraintAnnotation.value();
        if(value.length!=0){
            for (int val : value) {
                vals.add(val);
            }
        }
    }


    // 校验判断
    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
       return vals.contains(integer);
    }


}
